package at.horario.dao.hibernate;

import at.horario.dao.UserDao;
import at.horario.model.User;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: at
 * Date: 16/Set/2007
 * Time: 11:51:01
 * To change this template use File | Settings | File Templates.
 */
public class UserDaoHibernate extends GenericDaoHibernate<User, Long> implements UserDao {
    public UserDaoHibernate() {
        super(User.class);
    }

    public User findByUsername(String username) {
        DetachedCriteria criteria = DetachedCriteria.forClass(persistentClass);
        criteria.add(Restrictions.eq("username", username));
        List<User> l = getHibernateTemplate().findByCriteria(criteria, 0, 1);
        return l.isEmpty() ? null : l.get(0);
    }
}
